package com.czhoujunlv.drug.fragment;

import android.content.Intent;
import android.content.pm.LauncherApps;
import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.fragment.app.Fragment;

import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;

import com.czhoujunlv.drug.Abort;
import com.czhoujunlv.drug.Chat.Feedback;
import com.czhoujunlv.drug.Info;
import com.czhoujunlv.drug.R;
import com.czhoujunlv.drug.State.Payment;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.io.IOException;


public class MyFragment extends Fragment {

    ConstraintLayout info,payment,deliver_goods,transport,Receiving,feedback,abort,exit;
    TextView name,text1,text2,text3,text4;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_my, container, false);
        if (!EventBus.getDefault().isRegistered(this))
            EventBus.getDefault().register(this);
        return view;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        init();
        info.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getActivity(), Info.class);
                startActivity(intent);
            }
        });
        payment.setOnClickListener(new View.OnClickListener() {//代付款
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getActivity(), Payment.class);
                intent.putExtra("text",text1.getText().toString());
                startActivity(intent);
            }
        });
        deliver_goods.setOnClickListener(new View.OnClickListener() {//代发货
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getActivity(), Payment.class);
                intent.putExtra("text",text2.getText().toString());
                startActivity(intent);
            }
        });
        transport.setOnClickListener(new View.OnClickListener() {//运输中
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getActivity(), Payment.class);
                intent.putExtra("text",text3.getText().toString());
                startActivity(intent);
            }
        });
        Receiving.setOnClickListener(new View.OnClickListener() {//待收获
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getActivity(), Payment.class);
                intent.putExtra("text",text4.getText().toString());
                startActivity(intent);
            }
        });
        feedback.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getActivity(), Feedback.class);
                Toast.makeText(getActivity(),"进入客服",Toast.LENGTH_SHORT).show();
                startActivity(intent);
            }
        });
        abort.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getActivity(), Abort.class);
                startActivity(intent);
            }
        });
    }
    @Subscribe(threadMode = ThreadMode.MAIN)//子线程
    public void omThread(String event) throws IOException {
        String msg = event;
        name.setText(msg);
    }
    @Override
    public void onDestroy() {
        EventBus.getDefault().unregister(this);
        super.onDestroy();
    }
    private void init(){
        info = getActivity().findViewById(R.id.constraintLayout);
        name = getActivity().findViewById(R.id.textView20);
        text1 = getActivity().findViewById(R.id.text1);
        text2 = getActivity().findViewById(R.id.text2);
        text3 = getActivity().findViewById(R.id.text3);
        text4 = getActivity().findViewById(R.id.text4);

        payment = getActivity().findViewById(R.id.constraintLayout1);
        deliver_goods = getActivity().findViewById(R.id.constraintLayout60);
        transport = getActivity().findViewById(R.id.constraintLayout3);
        Receiving = getActivity().findViewById(R.id.constraintLayout4);

        feedback = getActivity().findViewById(R.id.constraintLayout50);
        abort = getActivity().findViewById(R.id.constraintLayout6);
        exit = getActivity().findViewById(R.id.constraintLayout7);

    }
}